﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class View_CIB_CIB001_Detail : ViewMatrix //ViewCIB001//System.Web.UI.Page
{
    System.Data.DataTable DT = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        serviceName = "MISAPP.Classify.Service.Service_CIB001";
        criteriaList = new string[] { "key", "Criteria", "ExclusiveOfAccount" };
        btn2Excel.PageParameter = "method=GetDetailData&xls=CIB001_Detail&service=Service_CIB001";
        GV1.PageSize = GetGridViewPageSize();
        if (!IsPostBack)
        {
            getData();
        }
    }

    protected void getData()
    {
        DT = GetDataFromSerevice("GetDetailData");
        GV1.DataSource = DT;
        GV1.DataBind();
    }
    protected void GV1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        Control_CIB001_Detail detail = null;
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            detail = e.Row.Cells[0].FindControl("CIB001_Detail1") as Control_CIB001_Detail;
            if (detail is Control_CIB001_Detail)
            {
                detail.SetValue(DT.Rows[GetCurrentTableRecord(GV1.PageIndex,e.Row.RowIndex,GV1.PageSize)], null);
            }
        }
    }

    protected void GV1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {        
        GV1.PageIndex = e.NewPageIndex;
        getData();
    }

    /// <summary>
    /// 取得目前要取出DataTable 中的那一筆，因為用GridView 來做分頁
    /// </summary>
    /// <param name="p_pageIndex"></param>
    /// <param name="p_rowIndex"></param>
    /// <returns></returns>
    protected int GetCurrentTableRecord(int p_pageIndex, int p_rowIndex,int p_pageSize)
    {
        int rtnValue = 0;
        if (p_pageIndex == 0)
        {
            rtnValue = p_rowIndex;
        }
        else
        {
            rtnValue = p_pageSize * p_pageIndex + p_rowIndex;
        }
        return rtnValue;
    }

    protected void btn2Excel_Click(object sender, EventArgs e)
    {
        FillToSession();
    }
}
